<?php 
require_once('includes/class.main.php');
$manager = new MeetingManager();
require_once('./includes/class.search.php');
require_once('./includes/class.geocode.php');

include_once 'template/header.php';

?>

<!DOCTYPE html>
<html lang="en">
<head>

	<?php MeetingManager::echoMetaData(); ?>

	<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=<? echo googleMapKey(); ?>&sensor=false" ></script>
	<script type="text/javascript" src="javascript/mtgbldr.js"></script>
  
	<script type="text/javascript">

		<?php 
		
		$address = (isset($_GET['address'])) ? $_GET['address'] : "";
		$address = preg_replace('/"/', '\"', $address);
		$city = (isset($_GET['city'])) ? $_GET['city'] : "";
		$city = preg_replace('/"/', '\"', $city);
		$zip = (isset($_GET['zip'])) ? $_GET['zip'] : "";
		$zip = preg_replace('/"/', '\"', $zip);
		$searchAddress = (isset($_GET['searchAddress'])) ? $_GET['searchAddress'] : "";
		$searchAddress = preg_replace('/"/', '\"', $searchAddress);
				
		$url = "http://" . $_SERVER['SERVER_NAME'] . "/api/searchmeetings.php?" . $_SERVER['QUERY_STRING'];
		
		?>

	  	var builder = new MeetingListBuilder();
	  	
  		builder.defaultLatLng = new google.maps.LatLng(
								  			<?php echo MeetingSearch::DEFAULT_LAT; ?>,
								  			<?php echo MeetingSearch::DEFAULT_LNG; ?>); 
		builder.defaultAddress = new Address(
											"<?php echo MeetingSearch::DEFAULT_ADDRESS; ?>",
	  										"<?php echo MeetingSearch::DEFAULT_CITY; ?>",
	  		  								"<?php echo MeetingSearch::DEFAULT_ZIP; ?>");				 		  		  	
  	    builder.queryURL = "<?php echo $url; ?>";
  		builder.markerIcons = 
  			[
  				"images/marker_1.png",
  				"images/marker_2.png",
  				"images/marker_3.png",
  				"images/marker_4.png",
  				"images/marker_5.png",
  				"images/marker_6.png",
  				"images/marker_7.png",
  				"images/marker_8.png",
  				"images/marker_9.png"
  		    ];
  		builder.defaultMarkerIcon = "images/red-circle-lv.png";

  		builder.searchAddress = "<?php echo $searchAddress; ?>";    
  	    builder.searchLocation.address.address = "<?php echo $address; ?>";
  		builder.searchLocation.address.city = "<?php echo $city; ?>";
  		builder.searchLocation.address.zip = "<?php echo $zip; ?>";
  		builder.searchLocation.markerIcon = "images/marker_star.png";
  	    
		builder.mapElem = "mapContent";
		builder.resultsElem = "searchResults";
		builder.messageElem = "messages";				  	
	  	builder.sortOptionsElem = "sortOptions";

		builder.superOnQueryResults = builder.onQueryResults;
		
		builder.onQueryResults = function(results) { 

			this.superOnQueryResults.call(this, results);

			if (this.sortType == "location") { 
				$("#locationSort").prop('checked', true); 
			} else { 
				$("#daySort").prop('checked', true); 
			}
			
			$('input:radio[name=sortType]').on(navigator.userAgent.match(/msie/i) ? "propertychange" : "change", function(evt) {
	  		    evt.preventDefault();
	  		    _builder.onSortChanged(this.value);
	  		});
		};
	  	
	  	$(document).ready(function() {
			builder.buildMeetingList();
	  	});

	</script>
</head>

<body>

<div class="content">
  	<?php include_once 'template/menu.php'; ?>
	<p>
	<div class="subheader">
  	</div>
	<div class="center" >
	
	
		<div id="messages" style="width:20%;margin-right: auto; margin-left:auto; margin-bottom:1em">
		</div>
		
		<div id="mapContent" style="width: 700px; height: 400px; margin-right: auto; margin-left:auto;">
		</div>
		<div id="sortOptions" style="width: 200px; margin-top: 10px; margin-right: auto; margin-left:auto;">
			<form id="sortControl" class="results">
				<span class="results sortLabel">Sort By</span>
				<input type="radio" id="locationSort" name="sortType" value="location" />
				<span class="results sortLabel">Location</span>
				<input type="radio" id="daySort" name="sortType" value="daytime" />
				<span class="results sortLabel">Day / Time</span>;
			</form>
		</div>
		
	
		<div id="searchResults" style="width: 760px; margin-right: auto; margin-left:auto;">
		
		</div>
			<span style="font-style:italic; line-height:5em; float:right">Have a comment about our new Meetings Search? <a href="mailto:aaatlanta.org@gmail.com">Email us!</a></span>
		
	</div>	
	
	<br>
	<? include('template/footer.php'); ?>
</div>

</body>
</html>

